' Individual Disclosure Submission Script
Option Strict Off
imports System
imports Humans=PHSRAG.Insight21.Humans
imports PHSRAG.Insight21.BusinessObjects
imports FormsManagement = PHSRAG.Insight21.FormsManagement
imports System.Collections
imports Utility=PHSRAG.Utility

module Script
    sub Main()
		dim questionnaireAnswer as FormsManagement.QuestionnaireAnswer = Nothing
		dim totalOutsideActivityDays as Double = 0
		dim totalCash as Integer = 0
		dim annualEquity as Integer = 0
		dim aggregateTotalEquity as integer = 0
		dim totalPercentageEquity as Integer = 0
		dim outsideActivityCount as Integer = 0
		dim answers as ArrayList = Nothing
		Dim answer as FormsManagement.Answer 

		currentCOI.LoadQuestionnaireAnswers()
		currentCOI.IsPolicyViolated = false
		
		For Each questionnaireAnswer in currentCOI.QuestionnaireAnswers
			questionnaireAnswer.Highlight = false
			dim holdsFiduciaryPosition as Boolean = false
			dim noWritten as Boolean = false
			dim noCSRL as Boolean = false
			dim isNaturePharma as boolean = false
			dim isNatureFinancial as Boolean = false
			dim isNatureClinical as Boolean = false
			dim isPrivate as boolean = false
			If (questionnaireAnswer.QuestionnaireCategory = "QUESTCAT_COI_OA" And questionnaireAnswer.QuestionnaireVersion.Questionnaire.Name = "Your Outside Activities") Then
			'Chart I related rules
				outsideActivityCount = outsideActivityCount + 1
				'no. of days
				answers = questionnaireAnswer.GetAnswers("TimeSpent")
				dim timeSpent as Double = 0
				If (answers.Count > 0) Then
					timeSpent = Convert.ToDouble(answers(0).Value)
					totalOutsideActivityDays = totalOutsideActivityDays + timeSpent
					If (timeSpent > 53) then 
						questionnaireAnswer.Highlight = true
						currentCOI.IsPolicyViolated = true
					End If
				End If
				
				'Annual Cash Compensation
				answers = questionnaireAnswer.GetAnswers("AnnualCashComp")
				dim cash as Integer = 0
				If (answers.Count > 0) Then
					cash = Convert.ToInt32(answers(0).Value)
					totalCash = totalCash + cash
					If (cash > 30000) then 
						questionnaireAnswer.Highlight = true
						currentCOI.IsPolicyViolated = true
					End If
				End If
				
				'Annaul Equity
				answers = questionnaireAnswer.GetAnswers("AnnualEquity")
				dim equity as Integer = 0
				If (answers.Count > 0) Then
					equity = Convert.ToInt32(answers(0).Value)
					annualEquity = annualEquity + equity
					If (equity > 30000) Then
						questionnaireAnswer.Highlight = true
						currentCOI.IsPolicyViolated = true
					End If
				End If
				
				if (cash + equity > 30000) then
					questionnaireAnswer.Highlight = true
					currentCOI.IsPolicyViolated = true
				end if
				
				'Total Equity
				answers = questionnaireAnswer.GetAnswers("TotalEquityOwned")
				If (answers.Count > 0) Then
					dim totalEquity as Integer = 0
					totalEquity = Convert.ToInt32(answers(0).Value)
					aggregateTotalEquity = aggregateTotalEquity + totalEquity
				End If
				
				'Percentage Equity Owned
				answers = questionnaireAnswer.GetAnswers("TotalPercentEquityOwned")
				If (answers.Count > 0) Then
					dim percentageEquity as Integer = 0
					percentageEquity = Convert.ToInt32(answers(0).Value)
					totalPercentageEquity = totalPercentageEquity + percentageEquity
					If (percentageEquity > 1) Then
						questionnaireAnswer.Highlight = true
						currentCOI.IsPolicyViolated = true
					End If
				End If
				
				'Fiduciary Position
				answers = questionnaireAnswer.GetAnswers("Position")
				For Each answer In answers
					If answer.Value <> "None" Then
						holdsFiduciaryPosition = true
						questionnaireAnswer.Highlight = true
						currentCOI.IsPolicyViolated = true
						Exit For
					End If
				Next
				
				'Nature of Business
				answers = questionnaireAnswer.GetAnswers("BriefDescriptionofBusiness")
				For Each answer In answers
					If answer.Value = "COIBUSSDESC_PHARM" Then
						isNaturePharma = true
					Else If answer.Value = "COIBUSSDESC_FINANCIAL" Then
						isNatureFinancial = true
					Else If answer.Value = "COIBUSSDESC_CLINICAL" Then
						isNatureClinical = true
					End If
				Next
				
				'Written Agreement
				answers = questionnaireAnswer.GetAnswers("WrittenAgreement")
				If (answers.Count > 0) Then
					If (answers(0).Value = "N") Then
						noWritten = true
					Else If answers(0).Value = "Y" Then
						dim csrlAnswers = questionnaireAnswer.GetAnswers("CSRL")
						If (csrlAnswers.Count > 0) Then
							If (csrlAnswers(0).Value = "N") Then
								noCSRL = true
							End If
						End If
					End If
				End If
				
				'No Written Agreement
				If (noWritten Or noCSRL OR isNatureFinancial OR isNatureClinical) Then
					questionnaireAnswer.Highlight = true
					currentCOI.IsPolicyViolated = true
				End If
				
			End If
			
			'Private Companies
			answers = questionnaireAnswer.GetAnswers("Public")
			If (answers.Count > 0) Then
				If (answers(0).Value = "N") Then
					isPrivate = true
					questionnaireAnswer.Highlight = true
					currentCOI.IsPolicyViolated = true
				End If
			End If
			
		Next
		
		If (totalPercentageEquity > 1 OR annualEquity > 30000 OR totalCash > 30000 OR (annualEquity + totalCash > 30000) OR outsideActivityCount >= 5 OR totalOutsideActivityDays > 53) Then
			currentCOI.IsPolicyViolated = true
		End If
		
		'Aggregate Equity
		currentCOI.AggregateEquity = aggregateTotalEquity
		
		'Other Activities
		currentCOI.UpdateOtherActivities()
		
   	End Sub
	
end module